package com.redfootdev.horseskills;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.EntityType;
import org.bukkit.plugin.java.JavaPlugin;



public class PlayerDatabase extends Database {

	private JavaPlugin plugin;
	
	private enum Attr {
		NAME			("Name"),
		APPRAISAL		("Appraisal"),
		TAMING			("Horsemanship");

		private final String name;
		
		Attr(String name) {
			this.name = name;
		}

	}
	
	//
	// PlayerDatabase() - (constructor) in this constructor we use the 
	// generic database object but give it the name it will be saved under.  
	//
	public PlayerDatabase(JavaPlugin plugin) {
		super(plugin,"PlayerData");
		this.plugin = plugin;
	}
	
	 //
	 // getAppraisal() - Sets the Appraisal value(int) or assigns a default value(defval) if no original value was found.
	 // setAppraisal() - Gets the Appraisal value(int) from Metadata.
	 // hasAppraisal() - Checks to see if there is a Appraisal value(int) stored in Metadata.
	 //
	 public Skill getAppraisal(Entity entity) {
		 if(!hasAppraisal(entity)) {
			 Skill defval = new Skill();
			 setAppraisal(entity, defval);
		 }
		 return getAttributeSkill(entity, Attr.APPRAISAL.name);
	 }
	 public void setAppraisal(Entity entity, Skill value) {
		 this.setName(entity);
		 this.setAttribute(entity, Attr.APPRAISAL.name, value);
	 }
	 public boolean hasAppraisal(Entity entity) {
		 return hasAttribute(entity, Attr.APPRAISAL.name);
	 }

	 
	 //
	 // getTaming() - Sets the Taming value(int) or assigns a default value(defval) if no original value was found.
	 // setTaming() - Gets the Taming value(int) from Metadata.
	 // hasTaming() - Checks to see if there is a Taming value(int) stored in Metadata.
	 //
	 public Skill getHorsemanship(Entity entity) {
		 if(!hasHorsemanship(entity)) {
			 Skill defval = new Skill();
			 setHorsemanship(entity, defval);
		 }
		 return getAttributeSkill(entity, Attr.TAMING.name);
	 }
	 public void setHorsemanship(Entity entity, Skill value) {
		 this.setName(entity);
		 this.setAttribute(entity, Attr.TAMING.name, value);
	 }
	 public boolean hasHorsemanship(Entity entity) {
		 return hasAttribute(entity, Attr.TAMING.name);
	 }

	 public void setName(Entity entity)
	 {
		 this.setAttribute(entity,Attr.NAME.name,((Player)entity).getName());
	 }
	
}
